﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HandWriter.Controls
{
	class ColorCheckedEventArgs : EventArgs
	{
		private Color _color;

		public ColorCheckedEventArgs(Color color)
		{
			_color = color;
		}

		public Color Color
		{
			get { return _color; }
			set { _color = value; }
		}
	}

	class ToolStripColorItem : ToolStripMenuItem
	{
		private Color _color;
		private readonly EventHandler _onClickEvent;

		public ToolStripColorItem(Color col, EventHandler onClickEvent)
		{
			_color = col;
			_onClickEvent = onClickEvent;
			Text = col.ToKnownColor().ToString();
		}

		public Color ItemColor
		{
			get { return _color; }
			set { _color = value; }
		}

		protected override void OnPaint(PaintEventArgs e)
		{
			base.OnPaint(e);
			using(Brush b = new SolidBrush(ItemColor))
			{
				e.Graphics.FillRectangle(b, 6, 4, 14, 14);
			}
		}

		protected override void OnClick(EventArgs e)
		{
			if (_onClickEvent != null)
			{
				_onClickEvent(this, new ColorCheckedEventArgs(ItemColor));
			}
		}
	}
}
